package com.tgy.leetcode;

import java.util.*;

/**
 * @Author: tgy
 * @Date: 12/28/20 9:58 AM
 *  给定由开始时间和结束时间组成的会议时间间隔数组，请返回至少要几间会议室。
 *
 *  如:
 *  [[0, 30],[5, 10],[15, 20]],
 *  返回 2
 */
public class _252_会议室_I_01 {

    public int minMeetingRooms(int[][] meetingRooms) {

        if (meetingRooms == null || meetingRooms.length == 0 || meetingRooms[0].length == 0) {

            return 0;
        }

        Map<Integer,Integer> map = new TreeMap<>();

        for (int[] meetingRoom : meetingRooms) {

             map.put(meetingRoom[0],map.getOrDefault(meetingRoom[0],0) + 1);
             map.put(meetingRoom[1],map.getOrDefault(meetingRoom[1],0) - 1);
        }

        int rooms = 0, res = 0;

        for (Map.Entry<Integer, Integer> integerIntegerEntry : map.entrySet()) {

            res = Math.max(res,rooms += integerIntegerEntry.getValue());
        }

       return res;
    }
}
